using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class user_permisionDAO
{
		public static List<user_permisionBO> GetAll()
		{
			return CBO.FillCollection<user_permisionBO>(DataProvider.getInstance().getAll(TableName.user_permision, PagingHelper.CreateOrder(new OrderObject(user_permisionTable.screen_id, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<user_permisionBO> GetAllC()
		{
			List<user_permisionBO> list = new List<user_permisionBO>();
			if(DataCache.GetCache(CacheName.user_permision) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.user_permision) != null)
					{
						list = (List<user_permisionBO>)DataCache.GetCache(CacheName.user_permision);
					}
					else
					{
			list = CBO.FillCollection<user_permisionBO>(DataProvider.getInstance().getAll(TableName.user_permision, PagingHelper.CreateOrder(new OrderObject(user_permisionTable.screen_id, SortOrder.Desc))));
						DataCache.SetCache(CacheName.user_permision, list);
					}
				}
			}
			else
			{
					list = (List<user_permisionBO>)DataCache.GetCache(CacheName.user_permision);
			}
		return list;
		}
		public static int InsertUpdateDelete(user_permisionBO user_permision, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_user_permision, "@" + user_permisionTable.screen_id, user_permision.screen_id,user_permision.user_id,user_permision.permission, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.user_permision);
			}
			return rs;
		}
		public static int Insert(user_permisionBO user_permision)
		{
			 return InsertUpdateDelete(user_permision, ProviderAction.Insert);
		}
		public static int Update(user_permisionBO user_permision)
		{
			 return InsertUpdateDelete(user_permision, ProviderAction.Update);
		}
		public static int Delete(user_permisionBO user_permision)
		{
			 return InsertUpdateDelete(user_permision, ProviderAction.Delete);
		}
		public static int Delete(int screen_id)
		{
			user_permisionBO user_permision = new user_permisionBO(screen_id);
			return Delete(user_permision);
		}
	}
}